import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart';
import 'package:flutter_ncsjqz_getx/http/dio_service.dart';
import 'package:flutter_ncsjqz_getx/model/base_entity.dart';
import 'package:flutter_ncsjqz_getx/model/get_friend_entity.dart';
import 'package:flutter_ncsjqz_getx/util/get_user_util.dart';
import 'package:get/get.dart';

class SearchAddFriendLogic extends GetxController {
  GetFriendData getFriendData = GetFriendData();
  TextEditingController textEditingController = TextEditingController();

  search(phoneNum) async {
    var map = {
      "phoneNumber": phoneNum
    };
    GetFriendEntity getFriendEntity = await DioService<GetFriendEntity>().findFriend(map);
    if (getFriendEntity.code == 0) {
      getFriendData = getFriendEntity.data ?? GetFriendData();
    }
    update();
  }

  /// 添加好友
  friendApply(friendId,) async{
    var data = {
      "friendId":friendId,
      "friendUserId": friendId,
      "isInitiator": true,
      "friendType": 0,
      "userId": getUserUtil().userId,
    };
    BaseEntity baseEntity = await DioService<BaseEntity>().friendApply(data);
    BotToast.showText(text: baseEntity.code == 0?"已成功发送好友申请":"已成功发送好友申请",align: Alignment(0, -0.8),contentColor: Colors.black);
    update();
  }
}
